Component({
	data: {
		active: 0, // 记录当前选中的项
		list: [{
			pagePath: "/pages/index/index",
			text: "运动资讯",
			icon: 'smile-o',
		}, {
			pagePath: "/pages/shequ/post/post",
			text: "发布",
			icon: 'like-o',
		}, {
			pagePath: "/pages/sport/sport",
			text: "运动统计",
			icon: 'fire-o',
		}, {
			pagePath: "/pages/user/user",
			text: "个人中心",
			icon: 'user-o',
		}],
	},
	methods: {
		onChange(e) {
			const index = e.detail;
			console.log(index, 'e');
			this.setData({
				active: index // 更新当前选中的项
			});
			wx.switchTab({
				url: this.data.list[index].pagePath
			});
		},
		init() {
			const page = getCurrentPages().pop();
			const route = `/${page.route}`;
			const activeIndex = this.data.list.findIndex(item => item.pagePath === route);
			this.setData({
				active: activeIndex // 初始化时设置正确的选中项
			});
		}
	}
});